package com.example.mybatisdemo2.mapper;

import com.example.mybatisdemo2.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface UserInfoXMLMapper {

    List<UserInfo> queryUserInfos();

    //因为安装了插件,所以可以自动生成,但是要有对得上号的名字
    //当插件无法判断名字属于什么操作的时候,就会进行询问(增删改查)
    List<UserInfo> queryUserInfos2();

    //插入
    Integer insert(UserInfo userInfo);


    //更新
    Integer update(UserInfo userInfo);


    //删除
    Integer delete(Integer id);

    //通过一些条件进行插入
    Integer insertByCondition(UserInfo userInfo);
    //使用注解,不推荐(因为不会报错,或者报错不容易看出问题)
    @Insert("<script>insert into userinfo2(id,username," +
            "        <if test='password!=null'>" +
            "            password," +
            "        </if>" +
            "        age)" +
            "        values (#{id},#{username}," +
            "        <if test='password!=null'>" +
            "            #{password}," +
            "        </if>" +
            "        #{age})" +
            "</script>")
    Integer insertByCondition2(UserInfo userInfo);


    //where标签
    List<UserInfo> selectByCondition(UserInfo userInfo);

    //set
    Integer updateByCondition(UserInfo userInfo);


    //批量删除
    Integer deleteByCondition(List<Integer> ids);
}